import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { BaseService, DataRegisterService } from 'src/app/services';
import { EventManagerService } from 'src/app/services/event-manager.service';
import { OrganizationService } from 'src/app/services/organization.service';
import { UploadService } from 'src/app/services/upload.service';
import { EngineService } from '../../../services/engine.service';
import { BaseFieldComponent } from '../base-field/base-field.component';

@Component({
  selector: 'zepride-office-tool',
  templateUrl: './office-tool.component.html',
  styleUrls: ['./office-tool.component.less', '../field.common.less']
})
export class OfficeToolComponent extends BaseFieldComponent implements OnInit {
  buttonConfigList: IButtonConfigItem[] = [];
  constructor(
    protected engineService: EngineService,
    protected baseSvr: BaseService,
    protected eventSvr: EventManagerService,
    protected orgSvr: OrganizationService,
    public uploadService: UploadService,
    protected msg: NzMessageService,
    private router: Router,
    protected dataRegisterService: DataRegisterService
  ) {
    super(engineService, baseSvr, eventSvr, orgSvr, uploadService, msg, dataRegisterService);
  }

  ngOnInit(): void {
    this.buttonConfigList = this.componentData.extends.buttonList;
    this.buttonConfigList || (this.buttonConfigList = []);
  }

  btnClick(item: IButtonConfigItem) {
    if (item.event == 'innerPage') {
      this.router.navigate(['home/page/normal-page/' + item.pageId]);
    }
    else if (item.event == 'outsideUrl') {
      window.open(item.url);
    }
  }

}

interface IButtonConfigItem {
  icon: string;
  name: string;
  color: string;
  url?: string;
  pageId?: string;
  event: 'innerPage' | 'outsideUrl';
}
